package com.veeder.datacollection.rs232.response.handler;

import com.veeder.datacollection.exception.SyntaxException;
import com.veeder.datacollection.rs232.response.RS232Response;
import com.veeder.datacollection.rs232.response.TankResponseReport;
import com.veeder.datacollection.util.DataUtil;
import com.veeder.datacollection.util.DateUtil;

public class RS608RspHandler extends CmdRspParser{

	@Override
	public RS232Response parseCoreResponse(String coreResponse) throws SyntaxException {
		TankResponseReport<Float> result = null;
		try {
			result =new TankResponseReport<Float>();
			int position = 6;
			result.setTlsSysDate(
					DateUtil.convertToDate(coreResponse.substring(position, position += 10), DateUtil.DateFormat1));
			while (position < coreResponse.length()) {
				int tankId = Integer.parseInt(coreResponse.substring(position, position += 2));
				float value= DataUtil.hexToFloat(coreResponse.substring(position, position +=8));
				result.setTankReponse(tankId, value);
			}
		} catch (Exception e) {
			throw new SyntaxException(e.toString());
		}

		return result;
	}

}
